package org.collegegeek.android;

import java.util.ArrayList;

public class Network {

	private ArrayList<NetPoint> points;

	public Network(String bssid) {
		this.points = new ArrayList<NetPoint>();
	}

	public void addPoint(NetPoint n) {
		this.points.add(n);
	}

	public Point averageLocations() {
		float sumX = 0;
		float sumY = 0;
		for (int i = 0; i < points.size(); i++) {
			sumX += points.get(i).getX();
			sumY += points.get(i).getY();
		}
		return new Point(sumX / points.size(), sumY / points.size());
	}

	/**
	 * @return A new point, indicating the average location of all the acquired
	 *         data points
	 * 
	 * 
	 *         Averages a series of Points, but applies more weight to points
	 *         with a higher signal strength.
	 */
	public Point averageLocationsWithWeight() {
		float sumX = 0;
		float sumY = 0;
		float total = 0;
		NetPoint p;
		for (int i = 0; i < points.size(); i++) {
			p = points.get(i);
			sumX += (p.getX() * p.getSignalStrength());
			sumY += (p.getY() * p.getSignalStrength());
			total += p.getSignalStrength();
		}
		return new Point(sumX / total, sumY / total);
	}

}
